package com.yc.cloud.admin.controller;

import com.yc.cloud.admin.dto.request.AvatarsCreateParam;
import com.yc.cloud.admin.dto.request.AvatarsUpdateParam;
import com.yc.cloud.admin.service.AvatarsService;
import com.yc.cloud.admin.vo.AvatarsVo;
import com.yc.cloud.basic.api.CommonPage;
import com.yc.cloud.basic.api.ResponseResult;
import com.yc.cloud.basic.dto.BaseQueryParam;
import com.yc.cloud.entity.Avatars;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.val;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 数字人形象
 *
 * @author Yancy
 * @date 2024-03-10
 */
@RestController
@RequestMapping("/avatars")
@Api(value = "数字人形象", tags = "数字人形象接口")
public class AvatarsController {

    @Resource
    private AvatarsService avatarsService;


    @GetMapping
    @ApiOperation(value = "数字人形象列表", notes = "支持分页查询,字段模糊匹配,排序等")
    public ResponseResult<CommonPage<AvatarsVo>> list(BaseQueryParam param) {
        val result = avatarsService.list(param);
        return ResponseResult.success(CommonPage.restPage(result));
    }


    @GetMapping("{id}")
    @ApiOperation(value = "数字人形象详情", notes = "根据ID查询")
    public ResponseResult<AvatarsVo> get(@PathVariable @ApiParam(value = "ID", required = true) Long id) {
        val result = avatarsService.get(id);
        return ResponseResult.success(avatarsService.convertVo(result));
    }


    @PostMapping
    @ApiOperation(value = "添加数字人形象", notes = "添加")
    public ResponseResult<Avatars> create(@Validated @RequestBody AvatarsCreateParam param) {
        val result = avatarsService.create(param);
        return result != null ? ResponseResult.success(result) : ResponseResult.failed();
    }


    @ApiOperation(value = "删除数字人形象", notes = "通过ID删除")
    @DeleteMapping(value = "{id}")
    public ResponseResult<Boolean> delete(@PathVariable @ApiParam(value = "ID", required = true) Long id) {
        val result = avatarsService.delete(id);
        return result ? ResponseResult.success(true) : ResponseResult.failed();
    }


    @ApiOperation(value = "修改数字人形象", notes = "通过ID修改")
    @PutMapping(value = "{id}")
    public ResponseResult<Avatars> update(@PathVariable @ApiParam(value = "ID", required = true) Long id, @Validated @RequestBody AvatarsUpdateParam param) {
        val result = avatarsService.update(id, param);
        return result != null ? ResponseResult.success(result) : ResponseResult.failed();
    }
}
